
template<typename T>
SequenceGenerator<T>::SequenceGenerator() : m_nValue(0), m_bIsBounded(false) {
	m_nMinValue = std::numeric_limits<T>::min();
	m_nMaxValue = std::numeric_limits<T>::max();
}

template<typename T>
SequenceGenerator<T>::SequenceGenerator(T nInitialValue) : m_nValue(nInitialValue), m_bIsBounded(false) {
}

template<typename T>
SequenceGenerator<T>::SequenceGenerator(T nMinValue, T nMaxValue) : 
	m_nMinValue(nMinValue),m_nMaxValue(nMaxValue), m_nValue(nMinValue), m_bIsBounded(true)  {
}

template<typename T>
SequenceGenerator<T>::SequenceGenerator(T nInitialValue, T nMinValue, T nMaxValue) : 
	m_nMinValue(nMinValue),m_nMaxValue(nMaxValue), m_nValue(nInitialValue), m_bIsBounded(true)  {
	if ( m_nValue < m_nMinValue || m_nValue > m_nMaxValue)
		throw std::invalid_argument ( "Illegal initial value!");
}

template<typename T>
SequenceGenerator<T>::~SequenceGenerator() {
}

template<typename T>
T SequenceGenerator<T>::next(T nStep) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	m_nValue += nStep;
	if(isBounded()) {
		if ( m_nValue > m_nMaxValue ) {
			m_nValue = m_nMinValue;
		}
		if ( m_nValue < m_nMinValue ) {
			m_nValue = m_nMaxValue;
		}
	}
	return m_nValue;
}

template<typename T>
T SequenceGenerator<T>::operator++() {
	return next();
}

template<typename T>
T SequenceGenerator<T>::operator++(int) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	T nCurrent = current();
	next();
	return nCurrent;
}

template<typename T>
T SequenceGenerator<T>::operator--() {
	return next(-1);
}

template<typename T>
T SequenceGenerator<T>::operator--(int) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	T nCurrent = current();
	next(-1);
	return nCurrent;
}

template<typename T>
T SequenceGenerator<T>::current() {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	return m_nValue;
}

template<typename T>
bool SequenceGenerator<T>::isBounded() {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	return m_bIsBounded;
}

template<typename T>
void  SequenceGenerator<T>::setBounded(bool bValue) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	m_bIsBounded = bValue;
}

template<typename T>
T SequenceGenerator<T>::getCurrentValue() {
	return current();
}

template<typename T>
void SequenceGenerator<T>::setCurrentValue ( T nValue ) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	this->m_nValue = nValue;
	if(isBounded()) {
		if ( m_nMinValue > m_nValue ) {
			m_nValue = m_nMinValue; 
		}
		if ( m_nMaxValue < m_nValue ) {
			m_nValue = m_nMaxValue;
		}
	}	
}

template<typename T>
T SequenceGenerator<T>::getMinValue() {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	return this->m_nMinValue;
}

template<typename T>
void SequenceGenerator<T>::setMinValue ( T nValue ) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	this->m_nMinValue = nValue;
	if (m_nMinValue > m_nValue ) {
		m_nValue = m_nMinValue; 
	}
	setBounded (true);
}

template<typename T>
T SequenceGenerator<T>::getMaxValue() {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	return this->m_nMaxValue;
}

template<typename T>
void SequenceGenerator<T>::setMaxValue ( T nValue ) {
	boost::recursive_mutex::scoped_lock oLock(m_mxValue);
	this->m_nMinValue = nValue;
	if (m_nMaxValue < m_nValue ) {
		m_nValue = m_nMaxValue; 
	}
	setBounded (true);
}
